<?php
namespace Sales\Controller;
use Think\Verify;
use Think\Controller;
class LoginController extends Controller {

	//登录页面
    public function index(){

        
        layout(false);
        $this->display();
    }


    public function verify(){
        $Verify =     new Verify();
        //对指定的变量参数赋值，调整验证码效果
        $Verify->fontSize = 30;
        $Verify->length   = 4;
        $Verify->useNoise = false;
        //图片输出
        $Verify->entry();
    }

    //登录页面
    public function login(){
        $result = I('');
        $verify = $this->check_verify($result['verify']);
        if(!$verify){
            $this->error("验证码错误", '/Sales/Login/index');
        }
       
        $where['user_name'] = $result['username'];
        $where['password'] = md5($result['password']);
        $reslist = M('business')->where($where)->find();
        if($reslist){
            $_SESSION ["salesInfo"] = $reslist;
            $this->success("登录成功", U("/Sales/Keywords/index"));
        }else{
            $this->error("用户名密码错误", U("/Sales/Login/index"));
        }
        
    }


    public function table(){
		$this->display();
    }

    public function alerts(){
		$this->display();
    }


    //官网推首页
    public function ptindex(){
        $Page = new \Think\Page($count, 30);
        $Page->setConfig('theme', "%UP_PAGE% %LINK_PAGE% %DOWN_PAGE% %END%");
        $show = $Page->show(); // 分页显示输出

        
        $about = M('about')->where($where)->order('id desc')->limit($Page->firstRow . ',' . $Page->listRows)->select();

        $show = str_replace('<div>','',$show);
        $show = str_replace('current','on',$show);
        $show = str_replace('<<<','上一页<',$show);
        $show = str_replace('>>>','>下一页',$show);
        $show = str_replace('</div>','',$show);
        layout('Layout/twolayout');
        $this->assign("page", $show); // 赋值分页输出
        $this->display();
    }


    //验证码验证
    public function check_verify($code, $id = ''){
        $verify = new Verify();
        return $verify->check($code, $id);
    }


    public function Logout(){
        session('userInfo',null);
        $this->success("退出成功", U("/Sales/Login/index"));
        exit;
    }
}